#!/usr/bin/php                                                                                                     
<?PHP                                                                                                              
if (count($argv) < 2) {                                                                                            
    print "NOOP Usage: parse.agi <code>\n";                                                                        
    exit(1);                                                                                                       
}                                                                                                                  
$ext = $argv[1];                                                                                                   
                                                                                                                   
$SOAP = new SoapClient('http://192.168.3.103/PhoneService.asmx?WSDL');                                   
                                                                                                                   
# Make a request for call data                                                                                     
$response = $SOAP->GetPhoneSession(array('sessionUID'=>$ext), array('exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE,));                                                     
                                                                                                                   
$xml = simplexml_load_string($response->GetPhoneSessionResult->any);                                               
$values = $xml->attributes();                                                                                      
$enableCall = $values["EnableCall"];                                                                               
if($enableCall == "false")                                                                                         
{                                                                                                                  
        //Error or call not allowed                                                                                
        print "SET VARIABLE AUTH_SUCCESS 0\n";                                                                     
}                                                                                                                                                                                                                               
else                                                                                                               
{                                                                                                                  
        //$clientId = $values["clientId"];                                                                           
        //$ipAddress = $values["ipAddress"];                                                                         
        $companyPhone = $values["companyPhone"];                                                                   
        //$clientPhone = $values["clientPhone"];                                                                     
        //$waitAudio = $values["waitAudio"];                                                                         
        //$advertAudio = $values["advertAudio"];                                                                     
        $disconnectAfter = $values["disconnectAfter"];                                                             
        //$requestUrl = $values["requestUrl"];                                                                       
                                                                                                                   
        print "SET VARIABLE AUTH_SUCCESS 1\n";                                                                     
//        print "SET VARIABLE __CLIENT_ID $clientId\n";                                                              
  //      print "SET VARIABLE __USER_IP $ipAddress\n";                                                               
          print "SET VARIABLE __COMPANY_PHONE $companyPhone\n";                                                      
        //print "SET VARIABLE __CUSTOMER_PHONE $clientPhone\n";                                                      
//        print "SET VARIABLE __ONWAIT $waitAudio\n";                                                                
//        print "SET VARIABLE __ADV $advertAudio\n";                                                                 
        print "SET VARIABLE __TIMEOUT $disconnectAfter\n";                                                         
//        print "SET VARIABLE __REQUEST_URL $requestUrl\n";                                                          
}                                                                                                                  
?>                                                                                                                 
                         

